import request from "@/utils/request.js";
import qs from "qs";

const baseUrl = '/adam4/api/v1/conceptBoardIndex';


/**
 * 前一个交易日的日期
 * @param {*} params 
 * @returns 
 */
function _previousDate(params) {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/previousDate/" + params,
      method: "GET"
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function previousDate(params) {
  let res = await _previousDate(params);
  return res;
};

/**
 * 后一个交易日的日期
 * @param {*} params 
 * @returns 
 */
function _nextDate(params) {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/nextDate/" + params,
      method: "GET"
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function nextDate(params) {
  let res = await _nextDate(params);
  return res;
};

/**
 * 根据开始时间和结束时间，计算平均KD值
 * @param {*} params 
 * @returns 
 */
function _findAverageKDByBeginDateAndEndDate(params) {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/findAverageKDByBeginDateAndEndDate",
      method: "POST",
      data: params
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function findAverageKDByBeginDateAndEndDate(beginDate, endDate) {
  let res = await _findAverageKDByBeginDateAndEndDate(beginDate, endDate);
  return res;
};

/**
 * 根据开始时间和结束时间，查询某个概念板块的KD值
 * @param {*} params 
 * @returns 
 */
function _findKdByMyquantCodeAndBeginDateAndEndDate(params) {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/findKdByMyquantCodeAndBeginDateAndEndDate",
      method: "POST",
      data: params
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function findKdByMyquantCodeAndBeginDateAndEndDate(beginDate, endDate) {
  let res = await _findKdByMyquantCodeAndBeginDateAndEndDate(beginDate, endDate);
  return res;
};

/**
 * 获取最近的交易记录
 * @returns 
 */
function _findLatestConceptBoardIndex() {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/findLatestConceptBoardIndex",
      method: "GET"
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function findLatestConceptBoardIndex(beginDate, endDate) {
  let res = await _findLatestConceptBoardIndex(beginDate, endDate);
  return res;
};

/**
 * 根据myquant_code、begin_date和end_date，查询记录，并按照transaction_date列升序排列
 * @returns 
 */
function _findByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc(params) {
  return new Promise((resolve, reject) => {
    request({
      url: baseUrl + "/findByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc",
      method: "POST",
      data: params
    }).then((res) => {
      resolve(res)
    }).catch((err) => {
      reject(err)
    })
  })
};
export async function findByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc(params) {
  let res = await _findByMyquantCodeAndBeginDateAndEndDateOrderByTransactionDateAsc(params);
  return res;
};